<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>写文章</title>
    <div th:replace="admin/common::menu"></div>
    <link rel="stylesheet" th:href="@{/lib/editormd/css/editormd.min.css}">
</head>
<body>
<div id="app">
    <div class="main-wrapper">
        <div class="navbar-bg"></div>
        <!--导航栏-->
        <div th:replace="admin/common::headermenu"></div>
        <!--侧边栏-->
        <div th:replace="admin/common::leftmenu(5)"></div>
    </div>
    <div class="main-content">
        <section class="section">
            <h1 class="section-header">
                <div>写点什么吧...</div>
            </h1>
        </section>
        <div class="ui container">
            <form id="blog-form" th:action="@{/admin/addEssay}" method="post" class="ui form">
                <input type="hidden" name="published">
                <input type="hidden" name="id" th:value="${blog.id}">
                <div class="ui error message"></div>
                <div class="required field">
                    <input type="text" name="title" placeholder="标题" th:value="${blog.title}">
                </div>

                <div class="required field">
                    <div id="md-content" style="z-index: 1 !important;">
                        <textarea placeholder="博客内容" name="content" style="display: none" th:text="${blog.content}"></textarea>
                    </div>
                </div>

                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui selection dropdown">
                                <input type="hidden" name="type.id" th:value="${blog.type}==null ? '':${blog.type.id}">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div th:each="type,iterStat:${types}" class="item" th:data-value="${type.id}" th:text="${type.name}"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label>
                        <input type="text" name="firstPicture" placeholder="首图引用地址，请用http://开头，可省略" th:value="${blog.firstPicture}">
                    </div>
                </div>


                <div class="inline fields">
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommened" class="hidden" th:attr="checked=(${blog.recommened})">
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="appreciation" name="appreciation" checked class="hidden" th:attr="checked=(${blog.id}==null ? true:${blog.appreciation})">
                            <label for="appreciation">赞赏</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="comment" name="commentabled" checked class="hidden" th:attr="checked=(${blog.id}==null ? true:${blog.commentabled})">
                            <label for="comment">评论</label>
                        </div>
                    </div>
                </div>

                <div class="ui right aligned container">
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button id="save-btn" class="ui secondary button">保存</button>
                    <button id="publish-btn" class="ui teal button">发布</button>
                </div>
            </form>
        </div>
        <div style="height: 50px"></div>
    </div>
</div>
<div th:replace="admin/common::srciptmenu"></div>
<script th:src="@{/lib/editormd/editormd.min.js}"></script>
<script type="text/javascript">
    $(function () {
        //初始化markdown编辑器
        var contentEditor;
        $(function() {
            contentEditor = editormd("md-content", {
                width   : "100%",
                height  : 640,
                syncScrolling : "single",
                path    : "/lib/editormd/lib/"
            });

        });
        //分类下拉框
        $(".ui.dropdown").dropdown({
            on : 'hover'
        })

        //保存按钮点击事件
        $("#save-btn").click(function () {
            $("[name='published']").val(false);
            $("#blog-form").submit();
        })

        //发布按钮点击事件
        $("#publish-btn").click(function () {
            $("[name='published']").val(true)
            $("#blog-form").submit();
        })

        $(".ui.form").form({
            fields : {
                title : {
                    identifier : 'title',
                    rules: [{
                        type : 'empty',
                        prompt : '提示：请输入博客标题'
                    }]
                },
                content : {
                    identifier : 'content',
                    rules: [{
                        type : 'empty',
                        prompt : '提示：请输入博客内容'
                    }]
                },
                typeId : {
                    identifier : 'type.id',
                    rules: [{
                        type : 'empty',
                        prompt : '提示：请输入博客分类'
                    }]
                }
            }
        });
    })
</script>
</body>
</html>